// src/interceptors/api-response.interceptor.ts
import {
    CallHandler,
    ExecutionContext,
    Injectable,
    NestInterceptor,
  } from '@nestjs/common';
  import { Observable } from 'rxjs';
  import { map } from 'rxjs/operators';
  
  export interface ApiResponse<T> {
    retcode: number; // 状态码
    message: string; // 返回信息
    data: T; // 返回数据
  }
  
  @Injectable()
  export class ApiResponseInterceptor<T> implements NestInterceptor<T, ApiResponse<T>> {
    intercept(context: ExecutionContext, next: CallHandler): Observable<ApiResponse<T>> {
      return next.handle().pipe(
        map((data) => ({
          retcode: 200, // 默认成功状态码
          message: 'Success', // 默认成功消息
          data, // 返回的数据
        })),
      );
    }
  }